package com.cmfi.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cmfi.domain.HydroCylinder;

/**
 * Spring Data R2DBC repository for the ForkliftPart entity.
 */
@Mapper
public interface ForkliftPartInfoDao {
	
	/**
	 * Description 通过查询条件和排序字段进行查询。conditions如 where name="a" and gender="b"
	 * pageInfo如：limit 2,3
	 * 
	 * @param conditions 如 where name="a" and gender="b"
	 * @param pageInfo   如：limit 2,3
	 * @return ForkliftPartInfo的list
	 */
	@Select("select * from (select * from forklift_part_info ${conditions}) forklift_plan_temp"
			+ "  order by createTime DESC ${pageInfo}")
	List<HydroCylinder> findByFilterConditionsAndPage(String conditions, String pageInfo);

	@Insert("insert into forklift_part_info(vinCode,partCode,partName,partType,position,username,createTime,updateTime) "
			+ " values(#{vinCode},#{partCode},#{partName},#{partType},#{position},#{username},#{createTime},"
			+ "#{updateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	void save(HydroCylinder entity);
	

//	@Update("update forklift_part_info set vinCode=#{vinCode},partCode=#{partCode},partName=#{partName},"
//			+ "partType=#{partType},partType=#{partType},position=#{position},username=#{username},"
//			+ "createTime=#{createTime},updateTime=#{updateTime} where id = #{id}")
	@Update("update forklift_part_info set partName=#{partName},"
			+ "partType=#{partType}"
			+ "where id = #{id}")
	void update(HydroCylinder entity);

	@Select("select * from forklift_part_info order by createTime DESC")
	List<HydroCylinder> findAll();

	@Select("select * from forklift_part_info where id=#{id}")
	HydroCylinder findById(Long id);
	
	@Select("select count(1) from forklift_part_info")
	long count();

	@Select("select * from forklift_part_info where vinCode=#{vinCode}")
    List<HydroCylinder> getForkliftPartsByVinCode (String vinCode);

	@Delete("delete from forklift_part_info where id = #{id}")
    void deleteById(Long id);

}
